package com.metacube.metaconnect.model;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.upload.FormFile;

public class SignUpStep2Form extends ActionForm {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String project_name;
	private String designation;
	private FormFile file;
	private String contact_number;

	public FormFile getFile() {
		return file;
	}

	public void setFile(FormFile file) {
		this.file = file;
	}

	public String getProject_name() {
		return project_name;
	}

	public void setProject_name(String project_name) {
		this.project_name = project_name;
	}

	public String getDesignation() {
		return designation;
	}

	public void setDesignation(String designation) {
		this.designation = designation;
	}

	public String getContact_number() {
		return contact_number;
	}

	public void setContact_number(String contact_number) {
		this.contact_number = contact_number;
	}

	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {

		ActionErrors errorList = new ActionErrors();
		if (file.getFileSize() == 0) {

		} else if (!file.getContentType().equals("image/jpeg")
				&& !file.getContentType().equals("image/png")
				&& !file.getContentType().equals("image/gif")) {
			errorList.add("file", new ActionMessage(
					"MetaConnect.error.file_type"));
		}
		/**
		 * If the file size is greater than 20kb.
		 */
		else if (file.getFileSize() > 20480 * 25) {
			errorList.add("file", new ActionMessage(
					"MetaConnect.error.file_size"));
		}

		if (!contact_number.matches("^[0-9]{10}$"))
			errorList.add("contact_number", new ActionMessage(
					"MetaConnect.error.contact"));

		if (request.getParameter("dob").trim().equals(""))
			errorList.add("dob", new ActionMessage("MetaConnect.error.dob"));
		return errorList;
	}

	@Override
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		project_name = "";
		designation = "";
		file = null;
		contact_number = "";
	}
}
